﻿using System;
using System.ComponentModel;
using System.Xml;

namespace YArchitech.Temp
{
	[DefaultProperty("Density")]
	public class PipeOption
	{
		[Category("参数设置")]
		[DisplayName("管壁粗糙度(m)")]
		[DefaultValue(0.0002)]
		public double Roughness { get; set; }

		[Category("参数设置")]
		[DisplayName("水温(℃)")]
		[DefaultValue(10)]
		public int Temperature { get; set; }

		[Category("自定义参数")]
		[DisplayName("运动黏度(㎡/s)")]
		[DefaultValue(1.57E-05)]
		public double Viscosity { get; set; }

		[Category("自定义参数")]
		[DisplayName("密度(kg/m³)")]
		[DefaultValue(999.73)]
		public double Density { get; set; }

		public static string ClassName
		{
			get
			{
				return "PipeOption";
			}
		}

		public PipeOption()
		{
			this.Roughness = 0.0002;
			this.Temperature = 10;
			this.Viscosity = 1.3E-06;
			this.Density = 999.73;
		}

		public void WriteXml(XmlWriter writer)
		{
			writer.WriteStartElement(PipeOption.ClassName);
			writer.WriteStartElement("Roughness");
			writer.WriteValue(this.Roughness);
			writer.WriteEndElement();
			writer.WriteStartElement("Viscosity");
			writer.WriteValue(this.Viscosity);
			writer.WriteEndElement();
			writer.WriteStartElement("Density");
			writer.WriteValue(this.Density);
			writer.WriteEndElement();
			writer.WriteStartElement("Temperature");
			writer.WriteValue(this.Temperature);
			writer.WriteEndElement();
			writer.WriteEndElement();
		}

		public void ReadXml(XmlReader reader)
		{
			reader.ReadStartElement(PipeOption.ClassName);
			reader.ReadStartElement("Roughness");
			this.Roughness = reader.ReadContentAsDouble();
			reader.ReadEndElement();
			reader.ReadStartElement("Viscosity");
			this.Viscosity = reader.ReadContentAsDouble();
			reader.ReadEndElement();
			reader.ReadStartElement("Density");
			this.Density = reader.ReadContentAsDouble();
			reader.ReadEndElement();
			reader.ReadStartElement("Temperature");
			this.Temperature = reader.ReadContentAsInt();
			reader.ReadEndElement();
			reader.ReadEndElement();
		}
	}
}
